package com.hxd.otc.module.convenience.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.module.convenience.bean.RefuelingServiceBean;
import com.hxd.otc.utils.DataUtils;
import com.hxd.otc.utils.GlideUtils;
import com.hxd.otc.utils.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

/**
 * Created by lzy on 2018/12/14 0014.
 * description ${视频类型Adapter}
 */
public class VideoTypeAdapter extends BaseAdapter<VideoTypeAdapter.VideoTypeHolder, RefuelingServiceBean> {

    private RefuelingServiceBean mSelItem;

    public VideoTypeAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull VideoTypeHolder holder, int position) {

        int screenWidth = DataUtils.getScreenWidth(mContext);
        ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
        layoutParams.width = getItemCount() > 4 ? (int) (screenWidth / 3.5f) : MATCH_PARENT;
        holder.itemView.setLayoutParams(layoutParams);

        RefuelingServiceBean item = getItem(position);
        holder.tvVideoName.setText(item.getModuleName());
        GlideUtils.setImage(mContext, UIUtils.getServiceImageUrlByPath(item.getModuleIcon()), R.mipmap.icon_convenience_default,
                R.mipmap.icon_convenience_default, holder.ivVideoLogo);

        holder.itemView.setSelected(item.equals(mSelItem));
    }

    @NonNull
    @Override
    public VideoTypeHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new VideoTypeHolder(mInflater.inflate(R.layout.item_video_type, parent, false));
    }

    public void setSelItem(RefuelingServiceBean selItem) {
        mSelItem = selItem;
        notifyDataSetChanged();
    }

    public RefuelingServiceBean getSelItem() {
        return mSelItem;
    }

    static class VideoTypeHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_video_logo)
        ImageView ivVideoLogo;
        @BindView(R.id.tv_video_name)
        TextView tvVideoName;

        VideoTypeHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
